//
//  ShotObject.m
//  Agility
//
//  Created by Dominique d'Argent on 17.03.11.
//  Copyright 2011 Nicky Nubbel. All rights reserved.
//

#import "ShotObject.h"

@implementation ShotObject

@synthesize target;

- (id)initWithPosition:(CGPoint)newPosition target:(GameObject *)newTarget trajectory:(CGFloat)newTrajectory {
    self = [super initWithImageNamed:[[self class] imageName]];
    
    if (self) {
        position    = newPosition;
        self.target = newTarget;
        trajectory  = newTrajectory;
        
        maxLifeTime     = 10.0;
        spawnTime       = 0.5;
        velocity        = 120.0f;
        angularVelocity = M_PI;
    }
    
    return self;
}

- (void)dealloc {
    [target release];
    
    [super dealloc];
}

+ (NSString *)imageName {
    return @"shot";
}

+ (void)spawnShotAtPosition:(CGPoint)newPosition withTarget:(GameObject *)newTarget trajectory:(CGFloat)newTrajectory {
    ShotObject *shot    = [[self alloc] initWithPosition:newPosition
                                                  target:newTarget
                                              trajectory:newTrajectory];
    
    NSString *shotKey = [[GameData sharedGameData] keyForNextShot];
    [[GameData sharedGameData] addGameObject:shot forKey:shotKey];
    
    [shot release];
}

@end
